<?php

namespace App\Http\Controllers;

use App\Services\Sms;
use App\Services\User;
use D1M\Common\Helpers\Result;
use Illuminate\Http\Request;

class UserController
{
    public function register(Request $request, User $service, Sms $sms)
    {
        $params = $request->only(['phone', 'code', 'realName', 'birthDay']);

        $checkCode = $sms->checkCode($params['phone'], $params['code']);
        if ($checkCode['error'])
            return Result::fail($checkCode['message'], $checkCode['code']);

        $result = $service->register($params);
        return $result['error'] ? Result::fail($result['message'] . "（需重发验证码）") : Result::success($result['data']);
    }
}